package com.njwb.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;

@Configuration
public class MyBatisPlusConfig {
    @Bean
    public MetaObjectHandler metaObjectHandler(){
        return new MetaObjectHandler() {
            @Override
            public void insertFill(MetaObject metaObject) {
                //fieldName是属性名，而不是数据库字段名
                this.strictInsertFill(metaObject,"createTime", LocalDateTime.class,LocalDateTime.now());
                this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());
            }
            @Override
            public void updateFill(MetaObject metaObject) {
                this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());
            }
        };
    }
}
